package com.xspace.android.xafcommon.network.message;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.apache.http.NameValuePair;

import com.xspace.android.xafcommon.network.NetConstant;
import com.xspace.android.xafcommon.network.exception.EncodeMessageException;

public abstract class ARequestMsg implements IRequestMsg {
	public int serialID;
	public boolean isBackgroud =false;
	public Hashtable params;
	public Hashtable otherDate;
	private static String enc = "UTF-8";
	private String contentType = "application/json";
	public List<NameValuePair> valuePair = new ArrayList<NameValuePair>();
	public int requestWay = 1;

	public ARequestMsg() {
		serialID = NetConstant.getSerialID();
	}

	@Override
	public void addNeedRespHeader() {
		params = new Hashtable();
		params.put("Accept", "application/json");
		params.put("Content-type", "application/json");

	}

	@Override
	public List<NameValuePair> getValuePair() {
		return valuePair;
	}

	@Override
	public String getContentType() {
		return contentType;
	}

	public final void setContentType(String contentType) {
		this.contentType = contentType;
	}

	@Override
	public int getRequestWay() {
		return requestWay;
	}

	@Override
	public byte[] getData() throws EncodeMessageException {
		return toBytes();
	}

	@Override
	public Hashtable getOtherDate() {
		if (otherDate == null) {
			otherDate = new Hashtable();
		}
		return otherDate;
	}

	@Override
	public int getSerId() {
		return serialID;
	}

	protected abstract String toJson();

	protected abstract byte[] toBytes();

}
